home *** CD-ROM | disk | FTP | other *** search
/ APDL Other Worlds / APDL Other Worlds Collection.iso / SF3000 / Extras / CBlibrary / h / RoundRobin < prev    next >
Encoding:
Text File  |  2003-10-12  |  2.1 KB  |  64 lines

  1. /*
  2.  * CBLibrary - RoundRobin
  3.  * Copyright (C) 2003  Chris Bazley
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Lesser General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2.1 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * Lesser General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Lesser General Public
  16.  * License along with this library; if not, write to the Free Software
  17.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  */
  19.  
  20. /* Round-robin system for multiple threads that require null polls */
  21.  
  22. #ifndef RoundRobin_h
  23. #define RoundRobin_h
  24.  
  25. #include <stdbool.h>
  26. #include "kernel.h"
  27.  
  28. /*
  29.    A RoundRobinHandler function must return when the volatile bool
  30.    pointed to by *time_up goes 'true'. A RoundRobinHandler may
  31.    return early (thus relinquishing control to the next thread)
  32.    but if it does so consistently then it will receive less CPU time
  33.    overall than other threads.
  34. */
  35.  
  36. typedef void (RoundRobinHandler) (void                *handle,
  37.                                   const volatile bool *time_up);
  38.  
  39. /*
  40.    The time value (in centisenconds) is the MINIMUM amount of work that
  41.    we do per null event received from the Wimp. The actual granularity
  42.    cannot be enforced - it is the responsibility of each
  43.    RoundRobinHandler to return when the word pointed to by *time_up is
  44.    set (or before this).
  45. */
  46.  
  47. extern _kernel_oserror *RoundRobin_initialise(unsigned int time);
  48.  
  49. extern _kernel_oserror *RoundRobin_finalise(void);
  50.  
  51. /* Register thread */
  52. extern _kernel_oserror *RoundRobin_register(RoundRobinHandler *handler, void *handle);
  53.  
  54. /* Deregister thread */
  55. extern void RoundRobin_deregister(RoundRobinHandler *handler, void *handle);
  56.  
  57. /* Suspend ALL threads */
  58. extern void RoundRobin_suspend(void);
  59.  
  60. /* Resume ALL threads */
  61. extern void RoundRobin_resume(void);
  62.  
  63. #endif
  64.